﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Collections;
using log4net;
using WEB.BLL.Entities;
using WEB.Exceptions;

namespace WEB.BLL.Services
{
    #region UserService

    /// <summary>
    /// UserService object for Ibatis mapped table 'User'.
    /// </summary>
    public class UserService : IUserService
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(UserService).Name);
        private static volatile UserService _UserService = null;
        public static UserService GetInstance()
        {
            if (_UserService == null)
            {
                lock (typeof(UserService))
                {
                    if (_UserService == null) // double-check
                        _UserService = new UserService();
                }
            }
            return _UserService;
        }
        public UserService()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public IList<UserEntity> LoadAllExtra()
        {
            try
            {
                return ExecuteQueryForList<UserEntity>("UserLoadAllExtra", null);
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
        public IList<UserEntity> Find(UserEntity obj)
        {
            try
            {
                IList<UserEntity> resul = ExecuteQueryForList<UserEntity>("UserSearch", obj);
                return resul;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }

        public int UpdatePassword(UserEntity objE)
        {
            try
            {
                ExecuteUpdate("UserUpdatePass", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
        public UserEntity UserLoadCheckAcitve(UserEntity objE)
        {
            try
            {
                return ExecuteQueryForObject<UserEntity>("UserLoadCheckAcitve", objE);
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
                //throw new DBException(ex.Message, ex);
            }
        }
        public UserEntity InsertGetUserName(UserEntity obj)
        {
            try
            {
                return ExecuteQueryForObject<UserEntity>("UserInsert", obj);
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
        public int UpdateCheck(UserEntity objE)
        {
            try
            {
                ExecuteUpdate("UserUpdateCheck", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
    }
    #endregion
}
